package web.api.global.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import web.api.global.convertor.UserConvertor;
import web.api.global.message.LoginApiRequest;
import web.api.global.message.RegisterApiRequest;
import web.api.global.message.TokenApiResponse;
import web.base.user.facade.UserFacade;
import web.base.user.message.UserRequest;

/**
 * @author Jin Zheng
 * @since 1.0 2022-01-25
 */
@RestController
public class IndexControllerImpl implements IndexController {
	private UserFacade userFacade;

	public IndexControllerImpl() {
	}

    @Override
    public ResponseEntity<Void> register(RegisterApiRequest request) {
	    UserRequest userRequest = UserConvertor.toRequest(request);
		userFacade.register(userRequest);
        return ResponseEntity.noContent().build();
    }

    @Override
    public TokenApiResponse login(LoginApiRequest request) {
		UserRequest userRequest = UserConvertor.toRequest(request);
		userFacade.login(userRequest);

        return null;
    }

	@Autowired
	public void setUserFacade(UserFacade userFacade) {
		this.userFacade = userFacade;
	}
}
